import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

# diver = webdriver.Chrome()
# # diver.implicitly_wait(10)  # 隐式等待：一次设置全局生效；只能判断元素是否出现，不能判断元素是否就绪
# diver.get("http://101.34.221.219:8010/?s=user/logininfo.html")
# el_btn = diver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/div/div/div[1]/form/div[3]/button')
# el_btn.click()
# # time.sleep(1)
# # 显式等待
# # 1、创建WebDriverWait对象
# wait = WebDriverWait(diver, 10)
#
#
# # 2、在函数中判断就绪条件
# def f(d):
#     # 如果就绪，返回True
#     # 如果没有就绪，返回False
#     el = d.find_element(By.XPATH, '/html/body/div[10]/div/p')
#     if el.text == "":
#         return False
#     return True
#
#
# # 3、把函数传递给对象，进行等待
# wait.until(f)
#
# el_a = diver.find_element(By.XPATH, '/html/body/div[10]/div/p')
# print(el_a.text)
# input()
# diver.quit()


# 表达式错误：id会变，将id在开发者工具中删除，再复制XPath
# diver = webdriver.Chrome()
# diver.get('https://element-plus.org/zh-CN/component/form.html#%E5%85%B8%E5%9E%8B%E8%A1%A8%E5%8D%95')
# el_a = diver.find_element(By.XPATH,
#                           '//*[@id="page-content"]/div/div/div[1]/div/div[3]/div[1]/form/div[1]/div[2]/div/div/input')
# el_a.screenshot("el.png")
# input()
# diver.quit()


# 无法交互，通过JS代码，绕过遮挡，模拟点击
driver = webdriver.Chrome()
driver.get('http://116.62.63.211/shop/goods/index/id/5.html')
el_a = driver.find_element(By.XPATH, '/html/body/div[4]/div[2]/div[2]/div/div[3]/div[2]/button[1]')
el_a.click()
time.sleep(2)
el_b = driver.find_element(By.XPATH, '/html/body/div[4]/div[2]/div[2]/div/div[3]/div[2]/button[1]')
# print(f"输出：{el_b}")
# el_b.click()
driver.execute_script("arguments[0].click()", el_b)
input()
driver.quit()
